package leetcode_top;

public class Ex198 {
    class Solution1 {
        public int rob(int[] nums) {
            int len = nums.length;
            int[][] f = new int[len][2];
            f[0][1] = nums[0];
            f[0][0] = 0;

            for (int i = 1; i < len; i++) {
                f[i][0] = Math.max(f[i - 1][0], f[i - 1][1]);
                f[i][1] = f[i - 1][0] + nums[i];
            }
            return Math.max(f[len - 1][0], f[len - 1][1]);
        }
    }

    class Solution {
        public int rob(int[] nums) {
            int len = nums.length;
            // int[][] f = new int[len][2];
            int rob = nums[0];
            int not = 0;

            for (int i = 1; i < len; i++) {
                int t = not;
                not = Math.max(rob, not);
                rob = t + nums[i];
            }
            return Math.max(rob, not);
        }
    }
}
